//
//  HGOderInfoCell.m
//  RedWinMall
//
//  Created by Henry on 2018/8/6.
//  Copyright © 2018年 HeDianZhao. All rights reserved.
//

#import "HGOderInfoCell.h"
#import "HGGoodsModel.h"

@implementation HGOderInfoCell {
    NSMutableArray <UILabel *> *rigthLabels;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
    }
    return self;
}

- (void)setModel:(HGGoodsModel *)model {
    _model = model;
    if (model == nil) return;
    NSString *payText = model.payWay == 1 ? @"支付宝" : @"微信";
    NSArray *datas = @[model.orderAmountRmb, @"自提", @"----",model.payAmountRmb,payText,@(model.no).description, kisStrNiL(model.createTime)];
    [rigthLabels enumerateObjectsUsingBlock:^(UILabel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.text = datas[idx];
        if (idx == 3) {
            obj.textColor = kColorMainTheme;
            obj.font = [UIFont systemFontOfSize:17];
        }
    }];
}

- (void)initSubViews {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGFloat margin = 5;
    CGFloat leftMargin = 14;
    NSArray *leftTitle = @[@"商品总价",@"配送方式",@"蓝积分抵扣",@"实付金额",@"支付方式",@"订单编号",@"提交时间"];
    UIView *lineView;
    
    rigthLabels = [@[] mutableCopy];
    for (int i = 0; i < leftTitle.count; i++) {
        UILabel *leftLabel = [[UILabel alloc] init];
        leftLabel.font = [UIFont systemFontOfSize:12];
        leftLabel.text = leftTitle[i];
        leftLabel.textColor = kColorText;
        [self.contentView addSubview:leftLabel];
        
        [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(leftMargin);
            i < 4 ? make.top.offset(20 + i *(15 + margin)) : make.top.equalTo(lineView.mas_bottom).offset(20 + (i - 4) *(15 + margin));
        }];
        
        UILabel *rigthLabel = [[UILabel alloc] init];
        rigthLabel.font = [UIFont systemFontOfSize:12];
        rigthLabel.text = @"---";
        rigthLabel.textColor = kColorText;
        [self.contentView addSubview:rigthLabel];
        [rigthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(leftLabel);
            make.right.offset(-leftMargin);
        }];
        
        if (i == 3) {
            lineView = [[UIView alloc] init];
            lineView.backgroundColor = kColorBackground;
            [self.contentView addSubview:lineView];
            
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(self.contentView);
                make.top.equalTo(leftLabel.mas_bottom).offset(20);
                make.height.offset(leftMargin - 4);
            }];
        }
        
        [rigthLabels addObject:rigthLabel];
    }
    
    
    
}

@end
